package team.jaman.autosell.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import team.jaman.autosell.entity.Logger;
import team.jaman.autosell.entity.Users;
import team.jaman.autosell.service.LoggerService;
import team.jaman.autosell.service.UsersService;
import team.jaman.autosell.tools.CommonData;
import team.jaman.autosell.tools.PageData;

@Controller
@RequestMapping("logger")
public class LoggerController {
	@Resource
	LoggerService loggerService;
	

	/**
	 * 添加日志
	 */
	@RequestMapping(value = "add", method = RequestMethod.POST)
	public CommonData addLogger(@RequestBody Logger record) {

		CommonData commonData = loggerService.addLogger(record);
		System.out.println(commonData.getMsg());

		return commonData;
	}

	/**
	 * 修改日志
	 */
	@RequestMapping(value = "update", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
	@ResponseBody
	public CommonData updateLogger(@RequestBody Logger record) {

		CommonData commonData = loggerService.updateByPrimaryKeySelective(record);
		System.out.println(commonData.getMsg());

		// indexManager 日志首页； addManager 添加日志页面资源
		return commonData;
	}

	/**
	 * 查询日志
	 */
	@ResponseBody
	@RequestMapping(value = "selectLike", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
	public PageData<Logger> selectLogger(@RequestParam(value = "page", defaultValue = "1") int page,@RequestParam(value = "limit", defaultValue = "10")  int limit,@RequestParam(value = "keyword", defaultValue = "") String keyword) {
		
		System.out.println("keyword:" + keyword);
		PageData<Logger> pageData = loggerService.selectLogger(page, limit, keyword);
		pageData.getData().forEach(users -> System.out.println(users));

		return pageData;
	}

}
